package com.homework;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class Method05 implements Runnable {
    BlockingDeque<String> blockingDeque;

    public Method05(BlockingDeque<String> blockingDeque) {
        this.blockingDeque = blockingDeque;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            System.out.println("123456");
            blockingDeque.putFirst("123456");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        System.out.println("Main Thread Start!");

        BlockingDeque<String> blockingDeque = new LinkedBlockingDeque<>();

        Method05 method05 = new Method05(blockingDeque);
        Thread t = new Thread(method05);
        t.start();

        System.out.println("异步处理结果为：" + blockingDeque.takeFirst());

        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");
        System.out.println("Main Thread End!");
    }
}
